package com.punch.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punch.system.mapper.SysHolidayMapper;
import com.punch.system.model.SysHoliday;
import com.punch.system.service.HolidayService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Service
public class HolidayServiceImpl extends ServiceImpl<SysHolidayMapper, SysHoliday> implements HolidayService {
    /**
     * 查找一定范围内的节假日
     *
     * @param startDay 开始日期
     * @param endDay   结束日期
     * @return 节假日
     */
    @Override
    public List<LocalDate> listHoliday(LocalDate startDay, LocalDate endDay) {
        QueryWrapper<SysHoliday> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().between(SysHoliday::getHoliday, startDay, endDay);
        List<LocalDate> holidayList = new ArrayList<>();
        list(queryWrapper).forEach(sysHoliday -> holidayList.add(sysHoliday.getHoliday()));
        return holidayList;
    }
}
